"""
开放商户 - 支付宝服务
"""

from jlpay.services.base_service import BaseService
from jlpay.model.openmerch.alipay.realname_ali_query import RealnameAliQueryRequest, RealnameAliQueryResponse


class AlipayService(BaseService):
    """开放商户支付宝服务"""
    
    def __init__(self, config):
        """
        初始化支付宝服务
        
        Args:
            config: OrgConfig实例
        """
        super().__init__(config)
    
    def get_api_url(self, request_class, api_path=None):
        """
        获取API URL
        
        Args:
            request_class: 请求类
            api_path: 接口路径
            
        Returns:
            完整的API URL
        """
        base_url = self.config.url
        
        if api_path:
            return f"{base_url}{api_path}"
        
        # 直接使用Request类中定义的完整API路径
        api_url = getattr(request_class, 'API_URL', '')
        
        if not api_url:
            # 如果没有定义API_URL，使用默认路径
            return f"{base_url}/open/merch/access/alipay"
        
        # 直接返回完整路径
        return f"{base_url}{api_url}"
    
    def query_realname_ali(self, request: RealnameAliQueryRequest) -> RealnameAliQueryResponse:
        """
        查询支付宝实名认证信息
        
        Args:
            request: RealnameAliQueryRequest实例
            
        Returns:
            RealnameAliQueryResponse: 支付宝实名查询响应
        """
        return self.post(request, RealnameAliQueryResponse) 